package com.xiaoxin.interceptor;

import com.xiaoxin.model.domain.User;

/**
 * @author xiaoxiaode
 * @date 2021-08-29-23:30
 **/
/*
 * 工具类:实现threadlocal存储数据的方法
 * */
public class UserHolder {

    private static ThreadLocal<User> tt = new ThreadLocal<>();

    //将当前用户,存入threadlocal
    public static void set(User user) {
        tt.set(user);
    }

    //从当前线程,获取用户对象
    public static User get() {
        return tt.get();
    }

    //从当前线程,获取用户对象的id
    public static Long getId() {
        return tt.get().getId();
    }

    //从当前线程,获取用户对象的手机号码
    public static String getMobile() {
        return tt.get().getMobile();
    }

    //清空threadlocal
    public static void remove() {
        tt.remove();
    }

    //更换手机号显示
    public static void setMobile(String phone) {
        tt.get().setMobile(phone);
    }
}
